package com.sumer.psychology.microblog.infrastructure.messaging.rabbitmq;

import com.sumer.psychology.common.port.adapter.messaging.Exchanges;
import com.sumer.psychology.common.port.adapter.messaging.rabbitmq.ExchangeListener;
import com.sumer.psychology.microblog.infrastructure.persistence.mongo.MongoMicroBlogRepository;

/**
 * 微博创建监听
 * <p/>
 * User: zhenguang.zhu
 * Date: 2014/10/10
 * Time: 8:49
 */
public class MicroBlogCreatedListener extends ExchangeListener {
    private MongoMicroBlogRepository mongoMicroBlogRepository;

    public MicroBlogCreatedListener(MongoMicroBlogRepository mongoMicroBlogRepository) {
        this.mongoMicroBlogRepository = mongoMicroBlogRepository;
    }

    @Override
    protected String exchangeName() {
        return Exchanges.DEFAULT_EXCHANGE_NAME;
    }

    @Override
    protected void filteredDispatch(String aType, String aTextMessage) {
        mongoMicroBlogRepository().add(aTextMessage);
    }

    @Override
    protected String[] listensTo() {
        return new String[]{"com.sumer.psychology.microblog.domain.model.MicroBlogCreatedEvent"};
    }

    public MongoMicroBlogRepository mongoMicroBlogRepository() {
        return mongoMicroBlogRepository;
    }
}
